﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CarCapacityDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarCapacityDB
    {
        public CarCapacityDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarCapacity carcapacity)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCapacityInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();
            _sPara.Add("@ProviderCarCCId", carcapacity.ProviderCCId);
            _sPara.Add("@ProviderCompanyId", carcapacity.ProviderCompanyId);
            _sPara.Add("@FromCCValue", carcapacity.FromCCValue);
            _sPara.Add("@ToCCValue", carcapacity.ToCCValue);
            _sPara.Add("@CCCodeValue", carcapacity.CCCodeValue);
            _sPara.Add("@CCRate", carcapacity.CCRate);
            _sPara.Add("@RefCEUserId", carcapacity.RefCEUserId);
            _sPara.Add("@Status", carcapacity.Status == true ? 1 : 0);
            _sPara.Add("@Finfo1", carcapacity.FInfo1);
            _sPara.Add("@Dinfo1", carcapacity.DInfo1);
            #region Parameter
            //_sPara.Add("@Info1", carcapacity.Info1);
            //_sPara.Add("@Info2", carcapacity.Info2);
            //_sPara.Add("@Info3", carcapacity.Info3);
            //_sPara.Add("@Info4", carcapacity.Info4);
            //_sPara.Add("@Info5", carcapacity.Info5);
            //_sPara.Add("@NInfo1", carcapacity.NInfo1);
            //_sPara.Add("@NInfo2", carcapacity.NInfo2);
            //_sPara.Add("@FInfo1", carcapacity.FInfo1);
            //_sPara.Add("@FInfo2", carcapacity.FInfo2);
            //_sPara.Add("@DInfo1", carcapacity.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public DataTable GetCarCapacityList(Int64 ProviderCompanyId, Int64 ProviderCCId)
        {
            DataTable _cclist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacitySelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@ProviderCarCCId", ProviderCCId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _cclist = _dt;
                }
            }
            return _cclist;
        }

        public DataTable GetCarCapacityList(Int64 ProviderCompanyId)
        {
            DataTable _cclist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacitySelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _cclist = _dt;
                }
            }
            return _cclist;
        }

        public CarCapacity GetCarCapacity(Int64 ProviderCCId)
        {
            CarCapacity _carcapacity = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCapacitySelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarCCId", ProviderCCId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carcapacity = new CarCapacity();
                    _carcapacity = FillDataRecord(_dt, 0);
                }
            }
            return _carcapacity;
        }

        private CarCapacity FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarCapacity myCarCapacity = new CarCapacity();
            myCarCapacity.ProviderCCId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarCCId"].ToString());
            myCarCapacity.ProviderCompanyId = Convert.ToInt32(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarCapacity.FromCCValue = Convert.ToInt16(myDataTable.Rows[RowId]["FromCCValue"].ToString());
            myCarCapacity.ToCCValue = Convert.ToInt16(myDataTable.Rows[RowId]["ToCCValue"].ToString());
            myCarCapacity.CCCodeValue = Convert.ToInt16(myDataTable.Rows[RowId]["CCCodeValue"].ToString());
            myCarCapacity.CCRate = Convert.ToSingle(myDataTable.Rows[RowId]["CCRate"].ToString());
            myCarCapacity.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarCapacity.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarCapacity.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarCapacity.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarCapacity.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarCapacity;
        }

        public bool Delete(Int64 ProviderCarCapacityId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCapacityDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarCCId", ProviderCarCapacityId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }
        
    }
}